package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void update(Orders orders);

    @Select("select * from orders where number = #{orderNumber}")
    Orders selectByNumber(String orderNumber);

    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);


    Page<Orders> selectHistoryWith(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer calculateNumByStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> selectByStatusAndOrderTimeLT(Integer status, LocalDateTime time);


    Integer selectByStatusAndOrderTimeGTE(Integer status, LocalDateTime time);

    Double getByStatusAndTime(Integer status, LocalDateTime beginTime, LocalDateTime endTime);

    Integer getOrderCount(Integer status, LocalDateTime beginTime, LocalDateTime endTime);
    @Select("select sum(amount) from orders where order_time between #{begin} and #{end} and status = #{status}")
    Double getTurnover(LocalDateTime begin, LocalDateTime end, Integer status);
}
